<?php

class WebUser extends CWebUser {
	/**
	 * @return boolean
	 */
	public function isAdmin(){
		return Yii::app()->getSession()->get('isAdmin');
	}
	
	/**
	 * @return Admin
	 */
	public function getAdminModel(){
		return $this->getModel();
	}
	
	/**
	 * @return Members
	 */
	public function getUserModel(){
		return $this->getModel();
	}
	
	/**
	 * @return CModel
	 */
	private function getModel() {
        return Yii::app()->getSession()->get('userModel');
    }

 	/**
	 * @param WebUserIdentity
	 * @param int
	 */
    public function login($identity, $duration) {
        parent::login($identity, $duration);
		Yii::app()->getSession()->add('isAdmin', $identity->getIsAdmin());
        Yii::app()->getSession()->add('userModel', $identity->getUserModel());
		$this->setId($identity->getId());
		$this->setName($identity->getUserName());
    }
 
 	/**
	 * @param boolean
	 */
    public function logout($destroySession= true) {
    	parent::logout($destroySession);
        Yii::app()->getSession()->remove('userModel');
    }
}
?>